/**
 * 箭头函数
 */
console.log('箭头函数常见用法');

//
const sz=["adsadsadad","aaaaa","adsadcccccccccccc","231313aaa"];
console.log(sz.map((sz)=> sz.length));

//
const a=1;
const b = 2;
const sum = () => a+b+100;
console.log(sum,sum());


const x=(a,b) => {
    const c=111;
    return a+b+c;
}
console.log(x,x(a,b));


const bob = (a) => a+1;
console.log(bob,bob(a));


const func = () => ({foo:1});
console.log(func,func());


const obj={
    i : 10,
   // b:() =>console.log(this.i,this),
    c(){
        console.log(this.i,this);
    },
};
//obj.b();
obj.c();


const obj1 = {
    a: 10,
};

Object.defineProperty(obj1, "b", {
    get: () => {
        console.log(this.a, typeof this.a, this); // undefined 'undefined' Window { /* … */ }（或全局对象）
        return this.a + 10; // 代表全局对象 'Window'，故 `this.a' 返回 'undefined'
    },
});


//关闭上下文
class C {
    a = 1;
    autoBoundMethod = () => {
        console.log(this.a);
    };
}

const c = new C();
c.autoBoundMethod(); // 1
const { autoBoundMethod } = c;
autoBoundMethod(); // 1

//使用剩余参数
function foo(n) {
    const f = (...args) => args[0] + n;
    return f(10);
}
console.log(foo(10));

//不用做构造函数
const Foo = () => {};
console.log("prototype" in Foo);  // 输出: false
//const foo = new Foo();  // 报错: TypeError: Foo is not a constructor



const obj2 = {
    count: 10,
    doSomethingLater() {
        setTimeout(function () {
            // 此函数在 window 作用域下执行
            this.count++;
            console.log(this.count);
        }, 300);
    },
};

obj2.doSomethingLater();// 输出“NaN”，因为count属性不在 window 作用域下。